/**
 * 
 */
package archsw0904.controller.shopping.common;

import java.math.BigDecimal;

import archsw0904.model.Book;


/**
 * @author ASGroup0904
 *
 */
public class BookInfo implements Comparable<Object> {
	
	private Integer id ;
	private String isbn ;
	private String author ;
	private String title ;
	private BigDecimal price ;
	private Integer copies ;
	private String year ; 
	
	public BookInfo ( Book book, Integer nCopies ) {
		this.id = book.getId() ;
		this.isbn = book.getIsbn() ;
		this.author = book.getAuthor() ;
		this.title = book.getTitle() ;
		this.price = book.getPrice() ;
		this.copies = nCopies ;
		this.year= book.getYear();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getIsbn() {
		return isbn;
	}

	public void setIsbn(String isbn) {
		this.isbn = isbn;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public Integer getCopies() {
		return copies;
	}

	public void setCopies(Integer copies) {
		this.copies = copies;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((author == null) ? 0 : author.hashCode());
		result = prime * result + ((copies == null) ? 0 : copies.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((isbn == null) ? 0 : isbn.hashCode());
		result = prime * result + ((price == null) ? 0 : price.hashCode());
		result = prime * result + ((title == null) ? 0 : title.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) return true;
		if (obj == null) return false;
		if (getClass() != obj.getClass()) return false;
		
		BookInfo other = (BookInfo) obj;
		if (author == null) { 
			if (other.author != null)
				return false;
		} else if (!author.equals(other.author))
			return false;
		if (copies == null) {
			if (other.copies != null)
				return false;
		} else if (!copies.equals(other.copies))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (isbn == null) {
			if (other.isbn != null)
				return false;
		} else if (!isbn.equals(other.isbn))
			return false;
		if (price == null) {
			if (other.price != null)
				return false;
		} else if (!price.equals(other.price))
			return false;
		if (title == null) {
			if (other.title != null)
				return false;
		} else if (!title.equals(other.title))
			return false;
		return true;
	}

	public BookInfo() {
		super();
	
		this.id = -1 ;
		this.isbn = "" ;
		this.author = null ;
		this.title = "" ;
		this.price = new BigDecimal(-1) ;
		this.copies = -1;
	}

	@Override
	public int compareTo(Object o) {
		BookInfo book = (BookInfo) o;
		if (book.getId()<= this.getId()) return 1;
		else return -1;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public String getYear() {
		return year;
	}


	
}
;